﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web.Mvc;
using Model.WaiGaoQiao;
using WaiGaoQiaoWeb.Models;
using WaiGaoQiaoWeb.JsonEntities;

namespace WaiGaoQiaoWeb.Controllers
{
    public class WarehouseSummaryController : Controller
    {

        public ActionResult WarehouseSummaryIndex()
        {
            ViewData["yy"] = GetOutstockYY();
            ViewData["mm"] = GetOutstockMM();
            ViewData["canteen"] = GetYaxNode();
            ViewData["type"] = GetType();
            ViewData["canteen1"] = GetYaxNode1();
            return View();
        }

        /// <summary>
        /// 获取年份列表
        /// </summary>
        /// <returns></returns>
        public IList<SelectListItem> GetOutstockYY()
        {
            IDictionary<int, string> dic = new Dictionary<int, string>();
            dic.Add(1, (DateTime.Now.Date.Year - 1).ToString());
            dic.Add(2, (DateTime.Now.Date.Year).ToString());
            dic.Add(3, (DateTime.Now.Date.Year + 1).ToString());
            IList<SelectListItem> selectList =
                dic.Select(m => new SelectListItem()
                {
                    Text = m.Value.ToString(),
                    Value = m.Key.ToString(),
                    Selected = (m.Value == (DateTime.Now.Date.Year).ToString()) ? true : false
                }).ToList();
            return selectList;
        }
        /// <summary>
        /// 获取月份列表
        /// </summary>
        /// <returns></returns>
        public IList<SelectListItem> GetOutstockMM()
        {
            IDictionary<int, string> dic = new Dictionary<int, string>();
            dic.Add(1, "1");
            dic.Add(2, "2");
            dic.Add(3, "3");
            dic.Add(4, "4");
            dic.Add(5, "5");
            dic.Add(6, "6");
            dic.Add(7, "7");
            dic.Add(8, "8");
            dic.Add(9, "9");
            dic.Add(10, "10");
            dic.Add(11, "11");
            dic.Add(12, "12");
            IList<SelectListItem> selectList =
                dic.Select(m => new SelectListItem()
                {
                    Text = m.Value.ToString(),
                    Value = m.Key.ToString(),
                    Selected = (m.Value == DateTime.Now.Month.ToString()) ? true : false
                }).ToList();
            return selectList;
        }
        /// <summary>
        /// 获取食堂列表
        /// </summary>
        /// <returns></returns>
        public IList<SelectListItem> GetYaxNode()
        {
            IDictionary<int, string> dic = new Dictionary<int, string>();
            YaxNodeInfo yaxinfo = new YaxNodeInfo(true);
            IList<YaxNodeInfo> yaxlist = yaxinfo.SelYaxNodeInfo("and CONFLAG=1");
            foreach (YaxNodeInfo yaxnode in yaxlist)
            {
                dic.Add(yaxnode.NodeID, yaxnode.Nodename);
            }
            IList<SelectListItem> selectList =
                dic.Select(m => new SelectListItem() { Text = m.Value.ToString(), Value = m.Key.ToString() }).ToList();
            return selectList;
        }

        /// <summary>
        /// 获取食堂列表
        /// </summary>
        /// <returns></returns>
        public IList<SelectListItem> GetYaxNode1()
        {
            IDictionary<int, string> dic = new Dictionary<int, string>();
            dic.Add(1, "一食堂主副调日班");
            dic.Add(2, "一食堂主副调夜班");
            dic.Add(3, "二食堂主副调早饭");
            dic.Add(4, "二食堂主副调中饭");
            IList<SelectListItem> selectList =
                dic.Select(m => new SelectListItem() { Text = m.Value.ToString(), Value = m.Key.ToString() }).ToList();
            return selectList;
        }

        /// <summary>
        /// 获取食材类型列表
        /// </summary>
        /// <returns></returns>
        public IList<SelectListItem> GetType()
        {
            IDictionary<int, string> dic = new Dictionary<int, string>();
            dic.Add(1, "主副");
            dic.Add(2, "调味品");
            IList<SelectListItem> selectList =
                dic.Select(m => new SelectListItem() { Text = m.Value.ToString(), Value = m.Key.ToString() }).ToList();
            return selectList;
        }

        /// <summary>
        /// 报表导出
        /// </summary>
        /// <returns></returns>
        public ActionResult StaffCanteenWarehouseOut1(string yy, string mm, string yax, string yaxname)
        {
            return EContent1(yy, mm, yax, yaxname);
        }

        public ExcelContentResult EContent1(string yy, string mm, string yax, string yaxname)
        {
            StringBuilder sBuilder = new StringBuilder();
            sBuilder.Append("<table cellspacing='0' cellpadding='5' rules='all' border='1'>");
            sBuilder.Append("<tr><td style='font-size:25px;'>" + yaxname + "</td></tr>");
            sBuilder.Append("<tr><td>");
            sBuilder.Append("<table cellspacing='0' cellpadding='5' rules='all' border='1' style='border:border-width;'>");
            sBuilder.Append("<tr style='font-size: 17px;'>");
            sBuilder.Append("<td>日期</td>");
            sBuilder.Append("<td>主</td>");
            sBuilder.Append("<td>副</td>");
            sBuilder.Append("<td>调</td>");
            sBuilder.Append("<td>合计</td>");
            sBuilder.Append("<td>收入</td>");
            sBuilder.Append("<td>盈亏</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr style='font-size: 14px;'>");
            sBuilder.Append("<td>4月21日</td>");
            sBuilder.Append("<td>200</td>");
            sBuilder.Append("<td>2.25</td>");
            sBuilder.Append("<td>100</td>");
            sBuilder.Append("<td>225.00</td>");
            sBuilder.Append("<td>2000</td>");
            sBuilder.Append("<td>4500.00</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr style='font-size: 14px;'>");
            sBuilder.Append("<td>4月22日</td>");
            sBuilder.Append("<td>200</td>");
            sBuilder.Append("<td>2.25</td>");
            sBuilder.Append("<td>100</td>");
            sBuilder.Append("<td>225.00</td>");
            sBuilder.Append("<td>2000</td>");
            sBuilder.Append("<td>4500.00</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr style='font-size: 14px;'>");
            sBuilder.Append("<td>4月23日</td>");
            sBuilder.Append("<td>200</td>");
            sBuilder.Append("<td>2.25</td>");
            sBuilder.Append("<td>100</td>");
            sBuilder.Append("<td>225.00</td>");
            sBuilder.Append("<td>2000</td>");
            sBuilder.Append("<td>4500.00</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("<tr style='font-size: 14px;'>");
            sBuilder.Append("<td>合计</td>");
            sBuilder.Append("<td>1200</td>");
            sBuilder.Append("<td>12.25</td>");
            sBuilder.Append("<td>1100</td>");
            sBuilder.Append("<td>1225.00</td>");
            sBuilder.Append("<td>12000</td>");
            sBuilder.Append("<td>14500.00</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("</table>");
            sBuilder.Append("</td>");
            sBuilder.Append("</tr>");
            sBuilder.Append("</table>");
            ExcelContentResult econtent = new ExcelContentResult();
            econtent.Content = sBuilder.ToString();
            econtent.filename = "StaffCanteenWarehouseOut1";
            econtent.ContentType = "application/ms-excel";
            econtent.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            return econtent;
        }

        /// <summary>
        /// 报表导出
        /// </summary>
        /// <returns></returns>
        public ActionResult StaffCanteenWarehouseOut(string yy, string mm, string yax, string type, string yaxname, string typename)
        {
            return EContent(yy, mm, yax, type, yaxname, typename);
        }

        public ExcelContentResult EContent(string yy, string mm, string yax, string type, string yaxname, string typename)
        {
            StringBuilder sBuilder = new StringBuilder();
            if (type == "1")
            {
                sBuilder.Append("<table cellspacing='0' cellpadding='5' rules='all' border='1'>");
                sBuilder.Append("<tr><td style='font-size:25px;'>员工食堂仓库汇总表</td></tr>");
                sBuilder.Append("<tr><td>");
                sBuilder.Append(yaxname + "（主食、副食）&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
                            "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
                            "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + yy + "年" + mm + "月");
                sBuilder.Append("</td></tr>");
                sBuilder.Append("<tr><td>");
                sBuilder.Append("<table cellspacing='0' cellpadding='5' rules='all' border='1' style='border:border-width;'>");
                sBuilder.Append("<tr style='font-size: 17px;'>");
                sBuilder.Append("<td>品名</td>");
                sBuilder.Append("<td>单位</td>");
                sBuilder.Append("<td>单价</td>");
                sBuilder.Append("<td colspan='2'>上月结存</td>");
                sBuilder.Append("<td colspan='2'>本月收入</td>");
                sBuilder.Append("<td colspan='2'>本月发出</td>");
                sBuilder.Append("<td colspan='2'>本月结存</td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("<tr style='font-size: 17px;'>");
                sBuilder.Append("<td></td>");
                sBuilder.Append("<td></td>");
                sBuilder.Append("<td></td>");
                sBuilder.Append("<td>数量</td>");
                sBuilder.Append("<td>金额</td>");
                sBuilder.Append("<td>数量</td>");
                sBuilder.Append("<td>金额</td>");
                sBuilder.Append("<td>数量</td>");
                sBuilder.Append("<td>金额</td>");
                sBuilder.Append("<td>数量</td>");
                sBuilder.Append("<td>金额</td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("<tr style='font-size: 14px;'>");
                sBuilder.Append("<td>大米</td>");
                sBuilder.Append("<td>斤</td>");
                sBuilder.Append("<td>2.25</td>");
                sBuilder.Append("<td>100</td>");
                sBuilder.Append("<td>225.00</td>");
                sBuilder.Append("<td>2000</td>");
                sBuilder.Append("<td>4500.00</td>");
                sBuilder.Append("<td>1900</td>");
                sBuilder.Append("<td>4275.00</td>");
                sBuilder.Append("<td>200</td>");
                sBuilder.Append("<td>450.00</td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("<tr style='font-size: 14px;'>");
                sBuilder.Append("<td colspan='3' style='font-weight: bold'>合计</td>");
                sBuilder.Append("<td>0</td>");
                sBuilder.Append("<td>225.0</td>");
                sBuilder.Append("<td>0</td>");
                sBuilder.Append("<td>11979.00</td>");
                sBuilder.Append("<td>0</td>");
                sBuilder.Append("<td>11754.00</td>");
                sBuilder.Append("<td>0</td>");
                sBuilder.Append("<td>450.00</td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("</table>");
                sBuilder.Append("</td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("<tr>");
                sBuilder.Append("<td style='height: 50px'></td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("<tr>");
                sBuilder.Append("<td>");
                sBuilder.Append("<table cellspacing='0' cellpadding='5' rules='all' border='1'>");
                sBuilder.Append("<tr style='font-size: 14px;'>");
                sBuilder.Append("<td>荤菜</td>");
                sBuilder.Append("<td>567</td>");
                sBuilder.Append("<td>76</td>");
                sBuilder.Append("<td>5675</td>");
                sBuilder.Append("<td>568</td>");
                sBuilder.Append("<td>2000</td>");
                sBuilder.Append("<td>345</td>");
                sBuilder.Append("<td>1900</td>");
                sBuilder.Append("<td>4275.00</td>");
                sBuilder.Append("<td>200</td>");
                sBuilder.Append("<td>450.00</td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("<tr style='font-size: 14px;'>");
                sBuilder.Append("<td>素菜</td>");
                sBuilder.Append("<td>567</td>");
                sBuilder.Append("<td>76</td>");
                sBuilder.Append("<td>5675</td>");
                sBuilder.Append("<td>568</td>");
                sBuilder.Append("<td>2000</td>");
                sBuilder.Append("<td>345</td>");
                sBuilder.Append("<td>1900</td>");
                sBuilder.Append("<td>4275.00</td>");
                sBuilder.Append("<td>200</td>");
                sBuilder.Append("<td>450.00</td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("<tr style='font-size: 14px;'>");
                sBuilder.Append("<td>鱼</td>");
                sBuilder.Append("<td>567</td>");
                sBuilder.Append("<td>76</td>");
                sBuilder.Append("<td>5675</td>");
                sBuilder.Append("<td>568</td>");
                sBuilder.Append("<td>2000</td>");
                sBuilder.Append("<td>345</td>");
                sBuilder.Append("<td>1900</td>");
                sBuilder.Append("<td>4275.00</td>");
                sBuilder.Append("<td>200</td>");
                sBuilder.Append("<td>450.00</td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("<tr style='font-size: 14px;'>");
                sBuilder.Append("<td>泡打粉</td>");
                sBuilder.Append("<td>567</td>");
                sBuilder.Append("<td>76</td>");
                sBuilder.Append("<td>5675</td>");
                sBuilder.Append("<td>568</td>");
                sBuilder.Append("<td>2000</td>");
                sBuilder.Append("<td>345</td>");
                sBuilder.Append("<td>1900</td>");
                sBuilder.Append("<td>4275.00</td>");
                sBuilder.Append("<td>200</td>");
                sBuilder.Append("<td>450.00</td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("<tr style='font-size: 14px;'>");
                sBuilder.Append("<td>水果</td>");
                sBuilder.Append("<td>567</td>");
                sBuilder.Append("<td>76</td>");
                sBuilder.Append("<td>5675</td>");
                sBuilder.Append("<td>568</td>");
                sBuilder.Append("<td>2000</td>");
                sBuilder.Append("<td>345</td>");
                sBuilder.Append("<td>1900</td>");
                sBuilder.Append("<td>4275.00</td>");
                sBuilder.Append("<td>200</td>");
                sBuilder.Append("<td>450.00</td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("<tr style='font-size: 14px;'>");
                sBuilder.Append("<td rowspan='2' colspan='3' style='font-weight: bold'>合计</td>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("<tr style='font-size: 14px;'>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("<tr style='font-size: 14px;'>");
                sBuilder.Append("<td colspan='3'>副调总合计</td>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("<td>206.00</td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("</table>");
                sBuilder.Append("</td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("<tr>");
                sBuilder.Append("<td>");
                sBuilder.Append("<table cellspacing='0' cellpadding='5' rules='all' border='1'>");
                sBuilder.Append("<tr style='font-size: 14px;'>");
                sBuilder.Append("<td>制表:</td>");
                sBuilder.Append("<td colspan='2'>张三</td>");
                sBuilder.Append("<td>主管:</td>");
                sBuilder.Append("<td></td>");
                sBuilder.Append("<td>会计:</td>");
                sBuilder.Append("<td colspan='2'></td>");
                sBuilder.Append("<td>复核:</td>");
                sBuilder.Append("<td colspan='2'></td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("</table>");
                sBuilder.Append("</td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("</table>");
            }
            else
            {
                sBuilder.Append("<table cellspacing='0' cellpadding='5' rules='all' border='1'>");
                sBuilder.Append("<tr><td style='font-size:25px;'>员工食堂仓库汇总表</td></tr>");
                sBuilder.Append("<tr><td>");
                sBuilder.Append(yaxname + "（调味品）&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
                            "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
                            "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + yy + "年" + mm + "月");
                sBuilder.Append("</td></tr>");
                sBuilder.Append("<tr><td>");
                sBuilder.Append("<table cellspacing='0' cellpadding='5' rules='all' border='1' style='border:border-width;'>");
                sBuilder.Append("<tr style='font-size: 17px;'>");
                sBuilder.Append("<td>品名</td>");
                sBuilder.Append("<td>单位</td>");
                sBuilder.Append("<td>单价</td>");
                sBuilder.Append("<td colspan='2'>上月结存</td>");
                sBuilder.Append("<td colspan='2'>本月收入</td>");
                sBuilder.Append("<td colspan='2'>本月发出</td>");
                sBuilder.Append("<td colspan='2'>本月结存</td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("<tr style='font-size: 17px;'>");
                sBuilder.Append("<td></td>");
                sBuilder.Append("<td></td>");
                sBuilder.Append("<td></td>");
                sBuilder.Append("<td>数量</td>");
                sBuilder.Append("<td>金额</td>");
                sBuilder.Append("<td>数量</td>");
                sBuilder.Append("<td>金额</td>");
                sBuilder.Append("<td>数量</td>");
                sBuilder.Append("<td>金额</td>");
                sBuilder.Append("<td>数量</td>");
                sBuilder.Append("<td>金额</td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("<tr style='font-size: 14px;'>");
                sBuilder.Append("<td>豆油</td>");
                sBuilder.Append("<td>桶</td>");
                sBuilder.Append("<td>2.25</td>");
                sBuilder.Append("<td>100</td>");
                sBuilder.Append("<td>225.00</td>");
                sBuilder.Append("<td>2000</td>");
                sBuilder.Append("<td>4500.00</td>");
                sBuilder.Append("<td>1900</td>");
                sBuilder.Append("<td>4275.00</td>");
                sBuilder.Append("<td>200</td>");
                sBuilder.Append("<td>450.00</td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("<tr style='font-size: 14px;'>");
                sBuilder.Append("<td colspan='3' style='font-weight: bold'>总合计</td>");
                sBuilder.Append("<td>0</td>");
                sBuilder.Append("<td>225.0</td>");
                sBuilder.Append("<td>0</td>");
                sBuilder.Append("<td>11979.00</td>");
                sBuilder.Append("<td>0</td>");
                sBuilder.Append("<td>11754.00</td>");
                sBuilder.Append("<td>0</td>");
                sBuilder.Append("<td>450.00</td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("</table>");
                sBuilder.Append("</td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("<tr>");
                sBuilder.Append("<td>");
                sBuilder.Append("<table cellspacing='0' cellpadding='5' rules='all' border='1'>");
                sBuilder.Append("<tr style='font-size: 14px;'>");
                sBuilder.Append("<td>制表:</td>");
                sBuilder.Append("<td colspan='2'>张三</td>");
                sBuilder.Append("<td>主管:</td>");
                sBuilder.Append("<td></td>");
                sBuilder.Append("<td>会计:</td>");
                sBuilder.Append("<td colspan='2'></td>");
                sBuilder.Append("<td>复核:</td>");
                sBuilder.Append("<td colspan='2'></td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("</table>");
                sBuilder.Append("</td>");
                sBuilder.Append("</tr>");
                sBuilder.Append("</table>");
            }
            ExcelContentResult econtent = new ExcelContentResult();
            econtent.Content = sBuilder.ToString();
            econtent.filename = "StaffCanteenWarehouseOut";
            econtent.ContentType = "application/ms-excel";
            econtent.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            return econtent;
        }
    }
}
